var layedit;
let index;
layui.use(['layedit', 'laydate', 'form', 'layer'],
    function () {
        $ = layui.jquery;
        var form = layui.form;
        layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '/upload' //接口url
                , type: '' //默认post
            }
        });
        index = layedit.build('content'); //建立编辑器

        findCuisineAll();

        findbyId();
    });

function findbyId() {
    let id = sessionStorage.getItem("productId");
    $.ajax({
        url: '/back/product/findById',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (res) {
            console.log(res)
            setProductData(res.data);
        }
    })
}

function setProductData(data) {
    layui.use(['form'],
        function () {
            $ = layui.jquery;
            var form = layui.form;

            $("#name").val(data.name);
            $("#normalPrice").val(data.normalPrice);
            $("#marketPrice").val(data.markedPrice);
            $("#cuisine").val(data.cuisineId);
            $("input[type=radio][name=isTop][value=" + data.isShow + "]").attr("checked", true);
            $("input[type=radio][name=isRecommend][value=" + data.isRecommend + "]").attr("checked", true);
            $("#demo1").attr("src", data.imgHref);

            // $("#content").val(data.content);
            layedit.setContent(index, data.content);

            form.render();
        });
}